import graphene
from flask import Flask
from flask_graphql import GraphQLView

class Person(graphene.ObjectType):
    first_name = graphene.String()
    last_name = graphene.String()

class Query(graphene.ObjectType):
    person = graphene.Field(Person)
    persons = graphene.List(Person)

    def resolve_person(self,info):
        # return Person(first_name="尚学堂",last_name="Mr.Li")
        return {"first_name":"尚学堂","last_name":"Mr.Gao"}
    def resolve_persons(self,info):

        # return Person(first_name="尚学堂",last_name="Mr.Li")
        return [
            {"first_name":"尚学堂","last_name":"Mr.Gao"},
            {"first_name":"尚学堂","last_name":"Mr.Li"}
        ]
if __name__ =='__main__':
    schema = graphene.Schema(query= Query)
    app = Flask(__name__)
    app.add_url_rule('/graphql',view_func=GraphQLView.as_view('grapql',schema=schema, graphiql=True))
    app.run(debug=True)